package com.duowei.diandan.callback;

import android.support.v7.util.DiffUtil;

import com.duowei.diandan.db.entry.Wmlsb;

import java.util.List;
import java.util.Objects;

public class CartChildDiffCallback extends DiffUtil.Callback {
    private final List<Wmlsb> mOldList;
    private final List<Wmlsb> mNewList;

    public CartChildDiffCallback(List<Wmlsb> oldList, List<Wmlsb> newList) {
        mOldList = oldList;
        mNewList = newList;
    }

    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        Wmlsb oldItem = mOldList.get(oldItemPosition);
        Wmlsb newItem = mNewList.get(newItemPosition);

        return oldItem.getId() == newItem.getId();
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        Wmlsb oldItem = mOldList.get(oldItemPosition);
        Wmlsb newItem = mNewList.get(newItemPosition);

        return Objects.equals(oldItem.getSl(), newItem.getSl())
                && Objects.equals(oldItem.getPz(), newItem.getPz());
    }
}
